﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlServerCe;

namespace WindowsFormsApplication1.Controller
{
    static class Control
    {
        public static DataTable Select(string q, string conn)
        {
            SqlCeDataAdapter dA = new SqlCeDataAdapter(q, conn);
            SqlCeCommandBuilder cBuilder = new SqlCeCommandBuilder(dA);
            DataTable dT = new DataTable();
            dA.Fill(dT);

            return dT;
        }

        public static int Insert_Update(string q, string conn, string[] x,string[] values)
        {
            SqlCeConnection cn = new SqlCeConnection(conn);

            try
            {
                cn.Open();
            }
            catch (SqlCeException ex)
            {
                return -1;
            }

            SqlCeCommand cmd = new SqlCeCommand(q,cn);
            for (int i = 0; i < values.Length; i++)
            {
                cmd.Parameters.AddWithValue(x[i], values[i]);
            }

            try
            {
                int affectedRows = cmd.ExecuteNonQuery();

                if (affectedRows > 0)
                {
                    return 1;

                }
                else
                {
                    return -1;
                }
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
    }
}
